package edu.usm.cs.roberge.views;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import edu.usm.cs.roberge.Message;

public class FavoritesTableModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private final List<Message> messages;
	
	public FavoritesTableModel(List<Message> messages) {
		this.messages = messages;
	}

	@Override
	public int getColumnCount() {
		return 2;
	}

	@Override
	public int getRowCount() {
		return messages.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		if (columnIndex == 0) {
			return messages.get(rowIndex).getNewsGroup().getNewsGroupName();
		} else {
			return messages.get(rowIndex).getSubjectHeader();
		}
	}

	@Override
	public String getColumnName(int column) {
		if (column == 0) {
			return "From News Group";
		} else {
			return "Subject";
		}
	}
	
	public void addMessage(Message message) {
		messages.add(message);
	}

	public void addMessages(List<Message> msgs) {
		messages.addAll(msgs);
	}

	public Message getMessageAtRow(int selectedRow) {
		if (selectedRow < 0) {
			return null;
		}
		
		return messages.get(selectedRow);
	}
}
